package com.taotao.rest.controller;

import com.taotao.pojo.TbItemCat;
import com.taotao.rest.service.ItemCatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.converter.json.MappingJacksonValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 商品分类列表
 * <p>Title: ItemCatController</p>
 * <p>Description: </p>
 * <p>Company: www.itcast.com</p>
 *
 * @author 入云龙
 * @version 1.0
 * @date 2015年9月7日下午3:02:39
 */
@Api(description = "商品分类")
@RestController
public class ItemCatController {

    @Autowired
    private ItemCatService itemCatService;

    @ApiOperation("通过父分类获取子分类")
    @GetMapping({"/itemcat/list/{parentId}",
            "/rest/itemcat/list/{parentId}"})
    public Object getItemCatList(String callback, @PathVariable long parentId) {
        List<TbItemCat> itemCatList = itemCatService.getItemCatList(parentId);
        if (callback != null && !"".equals(callback)) {
            MappingJacksonValue mappingJacksonValue = new MappingJacksonValue(itemCatList);
            mappingJacksonValue.setJsonpFunction(callback);
            return mappingJacksonValue;
        } else {
            return itemCatList;
        }
    }
}
